// 云函数入口文件
const cloud = require('wx-server-sdk')
cloud.init({
  env:"cloud2-4gncvam39e2323e9",
})
const db=cloud.database();

// 云函数入口函数
exports.main = async (event, context) => {
  
  const openid = cloud.getWXContext().OPENID
  const {userInfo}=event;
  userInfo.openid=openid;
  
  var res= await db.collection("userAll").where({
    openid:openid
  }).count()

  if(res.total>0){
    return await db.collection('userAll').where({
      openid
    }).update({
      data: userInfo
    })
  }else{
    return await db.collection('userAll').add({
      data: userInfo
    })
  }


}